/**
  ******************************************************************************
  * @file    Libraries/Device/TS32Fx/TS32Fx_LL_Driver/inc/ts32fx_ll_gpio.h
  * @author  TOPSYS Application Team
  * @version V1.0.0
  * @date    02-11-2018
  * @brief   This file contains all the GPIO LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2018 TOPSYS</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 
  
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TS32FX_LL_GPIO_H
#define __TS32FX_LL_GPIO_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "ts32fx.h"

/** @addtogroup TS32Fx_StdPeriph_Driver TS32Fx Driver
  * @{
  */
     
/** @addtogroup gpio_interface_gr GPIO Driver
  * @ingroup  TS32Fx_StdPeriph_Driver
  * @{
  */ 

/** @addtogroup GPIO_LL_Driver GPIO LL Driver
  * @ingroup  gpio_interface_gr
  * @brief Mainly the driver part of the GPIO module, which includes \b GPIO \b Register 
  * \b Constants, \b GPIO \b Exported \b Constants, \b GPIO \b Exported \b Struct, \b GPIO
  * \b Data \b transfers \b functions, \b GPIO \b Initialization \b and \b GPIO \b Configuration 
  * \b And \b Interrupt \b Handle \b function.
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/** @defgroup GPIO_LL_Register_Constants GPIO LL Register Constants
  * @ingroup  GPIO_LL_Driver
  * @brief    GPIO LL register constant table definition
  *
  *
@verbatim   
  ===============================================================================
                                Register Constants
  ===============================================================================  
  
    Register Constants mainly encapsulates each bit in each group in the GPIO 
    register. In the process of configuration, the macro definition can be directly 
    called to configure the GPIO register, mainly for convenience. Understand the 
    configuration of the GPIO.
    
@endverbatim
  *
  * @{
  */



/**
  * @}
  */

/** @defgroup GPIO_LL_Exported_Constants GPIO LL Exported Constants
  * @ingroup  GPIO_LL_Driver
  * @brief    GPIO LL external constant definition
  *
@verbatim   
  ===============================================================================
                                Exported Constants
  ===============================================================================  
  
    Exported Constants mainly restricts the partial configuration of the abstraction 
    layer by using the form of enumeration to facilitate the use and understanding of 
    the module configuration. For the specific enumeration meaning, please refer to 
    the annotation of each module.

@endverbatim
  *
  * @{
  */
  
/***** DRIVER API *****/
/*! Pin 0 selected */
#define LL_GPIO_PIN_0                 ((uint16_t)0x0001)
/*! Pin 1 selected */
#define LL_GPIO_PIN_1                 ((uint16_t)0x0002)
/*! Pin 2 selected */
#define LL_GPIO_PIN_2                 ((uint16_t)0x0004)
/*! Pin 3 selected */
#define LL_GPIO_PIN_3                 ((uint16_t)0x0008)
/*! Pin 4 selected */
#define LL_GPIO_PIN_4                 ((uint16_t)0x0010)
/*! Pin 5 selected */
#define LL_GPIO_PIN_5                 ((uint16_t)0x0020)
/*! Pin 6 selected */
#define LL_GPIO_PIN_6                 ((uint16_t)0x0040)
/*! Pin 7 selected */
#define LL_GPIO_PIN_7                 ((uint16_t)0x0080)
/*! Pin 8 selected */
#define LL_GPIO_PIN_8                 ((uint16_t)0x0100)
/*! Pin 9 selected */
#define LL_GPIO_PIN_9                 ((uint16_t)0x0200)
/*! Pin 10 selected */
#define LL_GPIO_PIN_10                ((uint16_t)0x0400)
/*! Pin 11 selected */
#define LL_GPIO_PIN_11                ((uint16_t)0x0800)
/*! Pin 12 selected */
#define LL_GPIO_PIN_12                ((uint16_t)0x1000)
/*! Pin 13 selected */
#define LL_GPIO_PIN_13                ((uint16_t)0x2000)
/*! Pin 14 selected */
#define LL_GPIO_PIN_14                ((uint16_t)0x4000)
/*! Pin 15 selected */
#define LL_GPIO_PIN_15                ((uint16_t)0x8000)
/*! All Pins selected */
#define LL_GPIO_PIN_All               ((uint16_t)0xFFFF)

/*******************  Bit definition for GPIO_MODER register  *****************/
/*! Gpio mode0 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER0          ((uint32_t)0x00000003)
/*! Gpio mode0 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER0_0        ((uint32_t)0x00000001)
/*! Gpio mode0 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER0_1        ((uint32_t)0x00000002)
/*! Gpio mode1 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER1          ((uint32_t)0x0000000C)
/*! Gpio mode1 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER1_0        ((uint32_t)0x00000004)
/*! Gpio mode1 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER1_1        ((uint32_t)0x00000008)
/*! Gpio mode2 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER2          ((uint32_t)0x00000030)
/*! Gpio mode2 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER2_0        ((uint32_t)0x00000010)
/*! Gpio mode2 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER2_1        ((uint32_t)0x00000020)
/*! Gpio mode3 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER3          ((uint32_t)0x000000C0)
/*! Gpio mode3 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER3_0        ((uint32_t)0x00000040)
/*! Gpio mode3 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER3_1        ((uint32_t)0x00000080)
/*! Gpio mode4 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER4          ((uint32_t)0x00000300)
/*! Gpio mode4 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER4_0        ((uint32_t)0x00000100)
/*! Gpio mode4 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER4_1        ((uint32_t)0x00000200)
/*! Gpio mode5 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER5          ((uint32_t)0x00000C00)
/*! Gpio mode5 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER5_0        ((uint32_t)0x00000400)
/*! Gpio mode5 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER5_1        ((uint32_t)0x00000800)
/*! Gpio mode6 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER6          ((uint32_t)0x00003000)
/*! Gpio mode6 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER6_0        ((uint32_t)0x00001000)
/*! Gpio mode6 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER6_1        ((uint32_t)0x00002000)
/*! Gpio mode7 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER7          ((uint32_t)0x0000C000)
/*! Gpio mode7 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER7_0        ((uint32_t)0x00004000)
/*! Gpio mode7 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER7_1        ((uint32_t)0x00008000)
/*! Gpio mode8 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER8          ((uint32_t)0x00030000)
/*! Gpio mode8 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER8_0        ((uint32_t)0x00010000)
/*! Gpio mode8 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER8_1        ((uint32_t)0x00020000)
/*! Gpio mode9 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER9          ((uint32_t)0x000C0000)
/*! Gpio mode9 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER9_0        ((uint32_t)0x00040000)
/*! Gpio mode9 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER9_1        ((uint32_t)0x00080000)
/*! Gpio mode10 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER10         ((uint32_t)0x00300000)
/*! Gpio mode10 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER10_0       ((uint32_t)0x00100000)
/*! Gpio mode10 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER10_1       ((uint32_t)0x00200000)
/*! Gpio mode11 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER11         ((uint32_t)0x00C00000)
/*! Gpio mode11 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER11_0       ((uint32_t)0x00400000)
/*! Gpio mode11 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER11_1       ((uint32_t)0x00800000)
/*! Gpio mode12 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER12         ((uint32_t)0x03000000)
/*! Gpio mode12 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER12_0       ((uint32_t)0x01000000)
/*! Gpio mode12 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER12_1       ((uint32_t)0x02000000)
/*! Gpio mode13 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER13         ((uint32_t)0x0C000000)
/*! Gpio mode13 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER13_0       ((uint32_t)0x04000000)
/*! Gpio mode13 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER13_1       ((uint32_t)0x08000000)
/*! Gpio mode14 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER14         ((uint32_t)0x30000000)
/*! Gpio mode14 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER14_0       ((uint32_t)0x10000000)
/*! Gpio mode14 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER14_1       ((uint32_t)0x20000000)
/*! Gpio mode15 bits 11 analog mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER15         ((uint32_t)0xC0000000)
/*! Gpio mode15 bits 01 general purpose output mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER15_0       ((uint32_t)0x40000000)
/*! Gpio mode15 bits 10 alternate function mode, reset state bits is 00 input mode
 */
#define LL_GPIO_MODER_MODER15_1       ((uint32_t)0x80000000)

/****************  Bit definition for GPIO_OSPEEDR register  ******************/
/*! gpio speed
 */
#define LL_GPIO_OSPEEDER_OSPEEDR0     ((uint32_t)0x0000000F)

/******************  Bit definition for GPIO_OTYPER register  *****************/
/*! Gpio output type0 set this bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_0           ((uint32_t)0x00000001)
/*! Gpio output type1 set this bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_1           ((uint32_t)0x00000002)
/*! Gpio output type2 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_2           ((uint32_t)0x00000004)
/*! Gpio output type3 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_3           ((uint32_t)0x00000008)
/*! Gpio output type4 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_4           ((uint32_t)0x00000010)
/*! Gpio output type5 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_5           ((uint32_t)0x00000020)
/*! Gpio output type6 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_6           ((uint32_t)0x00000040)
/*! Gpio output type7 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_7           ((uint32_t)0x00000080)
/*! Gpio output type8 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_8           ((uint32_t)0x00000100)
/*! Gpio output type9 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_9           ((uint32_t)0x00000200)
/*! Gpio output type10 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_10          ((uint32_t)0x00000400)
/*! Gpio output type11 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_11          ((uint32_t)0x00000800)
/*! Gpio output type12 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_12          ((uint32_t)0x00001000)
/*! Gpio output type13 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_13          ((uint32_t)0x00002000)
/*! Gpio output type14 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_14          ((uint32_t)0x00004000)
/*! Gpio output type15 bit 1 is open drain, reset state this bit is 0 push pull
 */
#define LL_GPIO_OTYPER_OT_15          ((uint32_t)0x00008000)
/*******************  Bit definition for GPIO_PUPDR register ******************/
/*! Gpio pull up and pull down pupdr0 bits 11 mark bits, reset state bits is 00 no pull
 */
#define LL_GPIO_PUPDR_PUPDR0          ((uint32_t)0x00000001)
/*! Gpio pull up and pull down pupdr8 bits 11 mark bits, reset state bits is 00 no pull
 */
#define LL_GPIO_PUPDR_PUPDR8          ((uint32_t)0x00010000)
/*! Gpio pin source0 pin index 0
 */
#define LL_GPIO_PIN_SOURCE_0           0x00
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_1           0x01
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_2           0x02
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_3           0x03
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_4           0x04
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_5           0x05
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_6           0x06
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_7           0x07
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_8           0x08
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_9           0x09
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_10          0x0A
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_11          0x0B
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_12          0x0C
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_13          0x0D
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_14          0x0E
/*! As above
 */
#define LL_GPIO_PIN_SOURCE_15          0x0F

/***** LL API *****/


  
/***** LL API AND DRIVER API *****/

/**
  * @brief Enumeration constant for GPIO pin alternate function select
  */
typedef enum {
    /*! Set GPIO Alternate Function 0
     */
    LL_GPIO_AF_0  = 0,
    /*! Set GPIO Alternate Function 1
     */
    LL_GPIO_AF_1,
    /*! Set GPIO Alternate Function 2
     */
    LL_GPIO_AF_2,
    /*! Set GPIO Alternate Function 3
     */
    LL_GPIO_AF_3,
} TYPE_ENUM_LL_GPIO_AF;

/**
  * @brief Enumeration constant for GPIO pin direction select
  */
typedef enum {             
    /*! Set GPIO to input mode.
     */
    LL_GPIO_PIN_INPUT,
    /*! Set GPIO to output mode.
     */
    LL_GPIO_PIN_OUTPUT,
} TYPE_ENUM_LL_GPIO_PIN_DIRECTION;

/**
  * @brief Enumeration constant for GPIO pin input output mode select
  */
typedef enum
{ 
    /*! GPIO Input Mode
     */
    LL_GPIO_MODE_IN   = 0x00,
    /*! GPIO Output Mode
     */
    LL_GPIO_MODE_OUT  = 0x01,
    /*! GPIO Alternate function Mode
     */
    LL_GPIO_MODE_AF   = 0x02,
    /*! GPIO Analog In/Out Mode
     */
    LL_GPIO_MODE_AN   = 0x03,
} TYPE_ENUM_LL_GPIO_MODE;

/**
  * @brief Enumeration constant for GPIO output type select
  */
typedef enum
{
    /*! Output push-pull (reset state)
     */  
    LL_GPIO_TYPE_OUT_PP = 0,
    /*! Output open-drain
     */
    LL_GPIO_TYPE_OUT_OD = 1,
} TYPE_ENUM_LL_GPIO_TYPE;

/**
  * @brief Enumeration constant for GPIO speed mode select
  */
typedef enum
{ 
    /*! gpioa speed mode voltage driving
     */
    LL_GPIO_SPEED_MODE_V  = 0x00,
    /*! gpioa speed mode current driving
     */
    LL_GPIO_SPEED_MODE_I  = 0x01, 
} TYPE_ENUM_LL_GPIO_SPEED_MODE;

/**
  * @brief Enumeration constant for GPIO speed level select
  */
typedef enum
{ 
    /*! gpioa/b/c low speed
     */
    LL_GPIO_SPEED_LEVEL_0  = 0x00,
    /*! gpioa/b/c speed 1
     */
    LL_GPIO_SPEED_LEVEL_1  = 0x01, 
    /*! gpioa speed 2, gpiob/c very high speed
     */
    LL_GPIO_SPEED_LEVEL_2  = 0x02,
    /*! gpioa speed 3, gpiob/c very high speed
     */
    LL_GPIO_SPEED_LEVEL_3  = 0x03,
    /*! gpioa speed 4, gpiob/c very high speed
     */
    LL_GPIO_SPEED_LEVEL_4  = 0x04,
    /*! gpioa speed 5, gpiob/c very high speed
     */
    LL_GPIO_SPEED_LEVEL_5  = 0x05,
    /*! gpioa speed 6, gpiob/c very high speed
     */
    LL_GPIO_SPEED_LEVEL_6  = 0x06,
    /*! gpioa high speed, gpiob/c very high speed
     */
    LL_GPIO_SPEED_LEVEL_7  = 0x07,
} TYPE_ENUM_LL_GPIO_SPEED_LEVEL;

/**
  * @brief Enumeration constant for GPIO pull up pull down select
  */
typedef enum
{
    /*! gpio no pull
     */
    LL_GPIO_PUPD_NOPULL = 0x00,
    /*! gpio pull up
     */    
    LL_GPIO_PUPD_UP     = 0x01,
    /*! gpio pull down
     */ 
    LL_GPIO_PUPD_DOWN   = 0x02,
} TYPE_ENUM_LL_GPIO_PUPD;


/** 
  * @brief  GPIO Bit SET and Bit RESET enumeration 
  */ 
typedef enum{
    /*! BIT_SET means to let the GPIO output a high level.
     */
    LL_GPIO_RESET = 0x00,
    /*! BIT_RESET means to let the GPIO output a low level.
     */
    LL_GPIO_SET,
} TPYE_ENUM_LL_GPIO_BIT_ACTION;

/**
  * @}
  */

/** @defgroup GPIO_LL_Exported_Struct GPIO LL Exported Struct
  * @ingroup  GPIO_LL_Driver
  * @brief    GPIO LL external configuration structure definition
  *
@verbatim   
  ===============================================================================
                                Exported Struct
  ===============================================================================  

    Exported Struct mainly extracts the GPIO registers from the API, and abstracts 
    the structure. As long as it implements the low coupling between the registers 
    and the registers, the user only needs to configure the structure of the abstraction 
    layer and call hal_gpio_init. Function, you can configure the GPIO module without 
    involving the configuration of the collective register.

@endverbatim
  *
  * @{
  */

/**
  * @brief GPIO Init low layer configuration structure
  */
typedef struct __type_ll_gpio_init {
    /*! Specifies the GPIO pins to be configured.  
     * This parameter can be any value of @ref gpio_pin define  
     */
    u16 gpio_pin;
    /*! Specifies the operating mode for the selected pins.  
     * This parameter can be a value of @ref gpio_mode define  
     */    
    TYPE_ENUM_LL_GPIO_MODE  gpio_mode;
    /*! Specifies the operating mode for the selected pins.  
     * This parameter can be a value of @ref gpio_type  
     */
    TYPE_ENUM_LL_GPIO_TYPE  gpio_type;
    /*! Specifies the voltage or current speed mode for the selected pins.  
     * This parameter can be a value of @ref gpio_speed_mode  
     */
    TYPE_ENUM_LL_GPIO_SPEED_MODE gpio_speed_mode;
    /*! Specifies the speed level for the selected pins.  
     * This parameter can be a value of @ref gpio_speed_level  
     */
    TYPE_ENUM_LL_GPIO_SPEED_LEVEL gpio_speed_level;
    /*! Specifies the pull up or down for the selected pins.  
     * This parameter can be a value of @ref gpio_pupd  
     */
    TYPE_ENUM_LL_GPIO_PUPD  gpio_pupd ;
} TYPE_LL_GPIO_INIT;
 

/**
  * @}
  */

/** @defgroup GPIO_LL_Interrupt GPIO LL Interrupt Handle function
  * @brief   GPIO LL Interrupt Handle function
  *
@verbatim   
  ===============================================================================
                        Interrupt Handle function
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the GPIO  
    Interrupt Handle function.

    how to use?

    The GPIO interrupt handler uses a callback method that reserves the interface 
    to the user in the form of a callback function. The client needs to initialize 
    the callback function when initializing the GPIO in order for the interrupt to 
    be processed normally. 
   
@endverbatim
  *
  * @{
  */



/**
  * @}
  */
  
/** @defgroup GPIO_LL_Inti_Cfg GPIO LL Initialization And Configuration
  * @brief    GPIO LL Initialization And Configuration
  *
@verbatim   
  ===============================================================================
                        Initialization And Configuration
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the GPIO data 
    Initialization and Configuration.
    
    how to use?

@endverbatim
  *
  * @{
  */

/**
  * @brief  Locks GPIO Group configuration registers.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @retval None.
  */
void ll_gpio_group_lock_config(GPIO_TypeDef* p_gpio);

/** 
  * @brief  Set the DIR value.
  * @param  p_gpio: where x can be (A..D) to select the GPIO peripheral.
  * @param  gpio_initstruct: gpio ll cfg instruct. 
  * @param  dir: The dir to be set.
  * @retval None.
  */
void ll_gpio_init(GPIO_TypeDef* p_gpio, TYPE_LL_GPIO_INIT* gpio_initstruct);

/**
  * @brief  Writes data to the specified GPIO data port.
  * @param  p_gpio: where x can be (A or C) to select the GPIO peripheral.
  * @param  gpio_pin_src: specifies the pin for the Alternate function.
  *          This parameter can be GPIO_PinSourcex where x can be (0..15).
  * @param  gpio_af: selects the pin to used as Alternate function.
  *          This parameter can be one of the following value:
  *            @arg GPIO_AF_0:  
  *            @arg GPIO_AF_1:  
  *            @arg GPIO_AF_2:  
  *            @arg GPIO_AF_3:  
  * @note   The pin should already been configured in Alternate Function mode(AF)
  *         using GPIO_InitStruct->GPIO_MODE = GPIO_MODE_AF.
  * @note   Refer to the Alternate function mapping table in the device datasheet 
  *         for the detailed mapping of the system and peripherals'alternate 
  *         function I/O pins.
  * @retval None.
  */
void ll_gpio_pin_af_config(GPIO_TypeDef* p_gpio, u16 gpio_pin_src, u16 gpio_af);

/**
  * @brief  Locks GPIO Pins configuration registers.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be written.
  *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  * @retval None.
  */
void ll_gpio_pin_lock_config(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Config gpio port toggle.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15). 
  * @retval None.
  */
void ll_gpio_port_toggle(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Reads the specified input port pin.
  * @param  p_gpio: where x can be (A, B, C) to select the GPIO peripheral.
  * @retval The input port pin value.
  */
u16 ll_gpio_read_input_data(GPIO_TypeDef* p_gpio);

/**
  * @brief  Sets the selected data port bits.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  * @retval None.
  */
void ll_gpio_set_bits(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Clears the selected data port bits.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  * @retval None.
  */
void ll_gpio_reset_bits(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Config gpio irq.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  * @param  newstate: DISABLE or ENABLE.
  * @retval None.
  */
void ll_gpio_irq_config(GPIO_TypeDef* p_gpio, u16 gpio_pin, FunctionalState newstate);

/**
  * @brief  Reads the specified input port pin.
  * @param  p_gpio: where x can be (A, B, C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to read.
  * @note   This parameter can be GPIO_Pin_x where x can be:(0..15) for GPIOA, 
  *         GPIOB or GPIOC,(0..2).
  * @retval The input port pin value.
  */
u8 ll_gpio_read_input_data_bit(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Reads the specified GPIO output data port.
  * @param  p_gpio: where x can be (A, B, C) to select the GPIO peripheral.
  * @retval GPIO output data port value.
  */
u16 ll_gpio_read_output_data(GPIO_TypeDef* p_gpio);

/**
  * @brief  Read the specified output data port bit.
  * @param  p_gpio: where x can be (A, B, C) to select the GPIO peripheral.
  * @param  gpio_pin: Specifies the port bit to read.
  * @note   This parameter can be gpio_pin where x can be:(0..15) for GPIOA, 
  *         GPIOB or GPIOC,(0..2) for GPIOD and(0..3) for GPIOF.
  * @retval The output port pin value.
  */
u8 ll_gpio_read_output_data_bit(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Write the specified output data port bit.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to read.
  *          This parameter can be GPIO_Pin_x where x can be (0..15).
  * @param  gpio_set_value: gpio set value.
  * @retval None.
  */
void ll_gpio_write_bit(GPIO_TypeDef* p_gpio,  u16 gpio_pin, TPYE_ENUM_LL_GPIO_BIT_ACTION gpio_set_value);

/**
  * @brief  Reads the specified GPIO output data port.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_set_value: gpio set value.
  * @retval None.
  */
void ll_gpio_write_data(GPIO_TypeDef* p_gpio, u32 gpio_set_value);

/**
  * @}
  */

/** @defgroup GPIO_LL_Data_Transfers GPIO LL Data transfers functions
  * @brief    GPIO LL Data transfers functions 
  *
@verbatim   
  ===============================================================================
                            Data transfers functions
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the GPIO data 
    transfers and receive.
  
@endverbatim
  *
  * @{
  */



/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

/**
  * @}
  */

/**
  * @}
  */

#endif //__TS32FX_LL_GPIO_H

/*************************** (C) COPYRIGHT 2018 TOPSYS ***** END OF FILE *****/
